<template>
  <div class="shop-love-box">
    <div class="love-box-header">
      <i class="el-icon-shopping-cart-full"></i>&nbsp;猜你喜欢>>>
    </div>
    <el-row
      :gutter="20"
      class="love-goods-container"
      type="flex"
      justify="space-around"
      style="flex-wrap: wrap"
    >
      <el-col :span="4" v-for="(item, index) in goodsInfo" :key="index">
        <div class="love-goods" @click="goBuy(item)">
          <img :src="item.imgUrl" class="love-img" />
          <span class="love-tittle">{{ item.title }}</span
          ><br />
          <div class="love-price-box">
            <span class="love-price1">￥{{ item.price }}</span
            >&nbsp;&nbsp;
            <span class="love-price2"
              >￥<del>{{ item.uprice }}</del></span
            >&nbsp;&nbsp;&nbsp;
            <span class="love-num">库存{{ item.num }}件</span>
          </div>
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import axios from "axios";
export default {
  data() {
    return {
      goodsInfo: [],
    };
  },
  methods: {
    goBuy(item) {
      this.$router.push({
        name: "buy",
        query: {
          product: JSON.stringify(item),
        },
      });
    },
  },
  //获取数据
  async mounted() {
    // 读取本地 goods.json 文件
    const res = await axios.get("/data/goods.json");
    this.goodsInfo = res.data;
    // console.log(this.goodsInfo);
  },
};
</script>

<style>
/* 猜你喜欢 */
.shop-love-box {
  width: 100%;
  background-color: #ffb188;
  display: flex;
  /* 自动换行 */
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
}

/* 喜爱头部 */
.love-box-header {
  margin-top: 1rem;
  /* background-color: skyblue; */
  width: 94%;
  font-size: 18px;
  font-weight: bolder;
  cursor: default;
}

/* 喜爱商品总容器 */
.love-goods-container {
  width: 96%;
  /* background-color: #fff; */
  margin-top: 1rem;
  margin-bottom: 2rem;
}

/* 单个商品 */
.love-goods {
  height: 18rem;
  margin-bottom: 1rem;
  min-height: 36px;
  border-top-left-radius: 25px;
  cursor: pointer;
  border: 2px solid #ffb188;
}

.love-goods:hover {
  border: 2px solid white;
}

/* 商品图片 */
.love-img {
  width: 100%;
  height: 13rem;
  border-top-left-radius: 25px;
}

/* 商品标题 */
.love-tittle {
  height: 3rem;
  font-weight: bolder;
}

/* 价格盒子 */
.love-price-box {
  height: 2rem;
  line-height: 200%;
}

.love-price1 {
  color: red;
  font-weight: bolder;
  font-size: large;
}

.love-price2 {
  color: #dfe0df;
}

.love-num {
  font-size: 10px;
  color: #dfe0df;
}
</style>